//
//  ProductInfoCell.m
//  AmazingShopping
//
//  Created by Tan on 4/24/13.
//  Copyright (c) 2013 Tan Hoang. All rights reserved.
//

#import "ProductInfoCell.h"

@implementation ProductInfoCell

@synthesize productName, sellerName, price, productNameLabel, sellerNameLabel, priceLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setProductName:(NSString *)pn{
    if (![productName isEqualToString:pn]) {
        productName = [pn copy];
        productNameLabel.text = productName;
    }
}

- (void)setSellerName:(NSString *)sn{
    if (![sellerName isEqualToString:sn]) {
        sellerName = [sn copy];
        sellerNameLabel.text = sellerName;        
    }
}

- (void)setPrice:(NSString *)pr{
    if (![price isEqualToString:price]) {
        price = [pr copy];
        priceLabel.text = [NSString stringWithFormat:@"$%@", price];
    }
}

- (void)reArrangingFrame{
    //Arrange Product Name Label
    CGSize maximumSize = CGSizeMake(productNameLabel.frame.size.width, 40);
    CGSize stringSize = [productNameLabel.text sizeWithFont:productNameLabel.font
                                          constrainedToSize:maximumSize
                                              lineBreakMode:productNameLabel.lineBreakMode];
    
    CGRect frame = CGRectMake(productNameLabel.frame.origin.x, productNameLabel.frame.origin.y, productNameLabel.frame.size.width, stringSize.height);
    
    productNameLabel.frame = frame;
    
    //Arrage Seller Name Label
    frame = CGRectMake(sellerNameLabel.frame.origin.x, productNameLabel.frame.size.height + 5, sellerNameLabel.frame.size.width, sellerNameLabel.frame.size.height);
    sellerNameLabel.frame = frame;
    
    //Arrage Price Label
    frame = CGRectMake(priceLabel.frame.origin.x, sellerNameLabel.frame.origin.y + sellerNameLabel.frame.size.height, priceLabel.frame.size.width, priceLabel.frame.size.height);
    priceLabel.frame = frame;
}

@end
